package com.example.sup.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sup.entity.Prison;
import com.example.sup.entity.PrisonJack;
import com.example.sup.entity.PrisonType;
import com.example.sup.service.PrisonJackService;
import com.example.sup.service.PrisonTypeService;
import com.example.sup.mapper.PrisonTypeMapper;
import com.example.sup.vo.PrisonConfigVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.List;

/**
* @author mac
* @description 针对表【prison_type(监室类型表)】的数据库操作Service实现
* @createDate 2024-07-19 10:05:17
*/
@Service
public class PrisonTypeServiceImpl extends ServiceImpl<PrisonTypeMapper, PrisonType>
    implements PrisonTypeService{
    @Resource
    private PrisonJackService jackService;

    @Override
    public List<PrisonConfigVO> queryPrisonTypeConfig() {
        List<PrisonConfigVO> prisonConfigVOS = new ArrayList<>();
        //1. 获取所有监室类型
        List<PrisonType> prisonTypes = this.list();

        //2. 根据监视室类型id查询Jack
        for (PrisonType prisonType : prisonTypes) {
            PrisonConfigVO prisonConfigVO = new PrisonConfigVO();
            prisonConfigVO.setPrisonType(prisonType);
            List<PrisonJack> prisonJacks = jackService.list(new QueryWrapper<PrisonJack>().eq("prison_type_id", prisonType.getPrisonTypeId()));
            prisonConfigVO.setPrisonJacks(prisonJacks);
            prisonConfigVOS.add(prisonConfigVO);
        }
        return prisonConfigVOS;
    }
}




